package com.atwisdom.star.test.starModel;

import cn.hutool.core.collection.CollectionUtil;
import com.atwisdom.star.common.util.UuidTool;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

public class test {//导入json解析库


    //定义一个方法，接受一个json字符串作为参数
    public static void printNameAndComments(String json) throws JSONException {
        //创建一个json数组对象，解析json字符串
        JSONArray array = new JSONArray(json);
        //遍历json数组中的每个元素，每个元素是一个json对象
        for (int i = 0; i < array.length(); i++) {
            //获取当前元素，转换为json对象
            JSONObject obj = array.getJSONObject(i);
            //从json对象中获取name和comments的值
            String name = obj.getString("name");
            String comments = obj.getString("comments");
            String type = obj.getString("type");
            if (type.equals("String")) {
                type = "字符";
            } else if (type.startsWith("Integer")) {
                type = "整型";
            } else if (type.startsWith("DateTime")) {
                type = "日期";
            }else if (type.startsWith("Double")) {
                type = "浮点";
            }


            //打印name和comments，用制表符分隔
            System.out.printf("%-20s %-20s %-20s %-20s\n", name,  type, " ", comments);
        }
    }

    private static boolean hasIntersection(Map<String, List<Integer>> map, List<Integer> knownList) {
        for (List<Integer> values : map.values()) {
            for (Integer value : values) {
                if (knownList.contains(value)) {
                    return true;
                }
            }
        }
        return false;
    }

    //在主方法中调用上面定义的方法，传入你给出的json字符串
    public static void main(String[] args) throws JSONException {
        String valueStr = "skdfjsldautoUuid.*";
        String prefix = valueStr.substring(valueStr.indexOf("autoUuid.") + "autouuid.".length());

        System.out.println( prefix+ UuidTool.getUUID32());


        Double a = 10.0;
        Double b=a;
        a= 100.0;
        System.out.println(a+"============="+b);


//
//        List<Integer> listA = Arrays.asList(1, 2);
//        List<Integer> listB = Arrays.asList(2, 3);
//        List<Integer> listC = Arrays.asList(3, 4);
//        List<Integer> listD = Arrays.asList(4, 5);
//
//        Map<String,List<Integer>> map = new HashMap<>();
//        map.put("A",listA);
//        map.put("B",listB);
//        map.put("C",listC);
//        map.put("D",listD);
//
//        List<Map<String,List<Integer>>> listMap = new ArrayList<>();
//        for (Map.Entry<String, List<Integer>> entry : map.entrySet()) {
//            List<Integer> value = entry.getValue();
//            String key = entry.getKey();
//            Boolean isIncluded = true;
//            for (Map<String,List<Integer>> lMap: listMap ) {
//                if(!hasIntersection(lMap, value)){
//                    lMap.put(key,value);
//                    isIncluded = false;
//                    break;
//                }
//            }
//
//            if(isIncluded){
//                Map<String,List<Integer>> tempMap = new HashMap<>();
//                tempMap.put(key,value);
//                listMap.add(tempMap);
//            }
//        }
//        System.out.println(listMap);





//
//        String json = "[\n" +
//                "  {\n" +
//                "    \"comments\": \"物料ID\",\n" +
//                "    \"defaultValue\": null,\n" +
//                "    \"name\": \"material_id\",\n" +
//                "    \"type\": \"Integer\",\n" +
//                "    \"group\": [\n" +
//                "      \"general\"\n" +
//                "    ]\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"comments\": \"物料名称\",\n" +
//                "    \"name\": \"material_name\",\n" +
//                "    \"type\": \"String\"\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": \"s0\",\n" +
//                "    \"comments\": \"品番\",\n" +
//                "    \"defaultValue\": \"\",\n" +
//                "    \"name\": \"material_pcode\",\n" +
//                "    \"type\": \"String\",\n" +
//                "    \"group\": [\n" +
//                "      \"general\"\n" +
//                "    ]\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": \"s1\",\n" +
//                "    \"comments\": \"背番\",\n" +
//                "    \"defaultValue\": \"\",\n" +
//                "    \"name\": \"material_bcode\",\n" +
//                "    \"type\": \"String\",\n" +
//                "    \"group\": [\n" +
//                "      \"general\"\n" +
//                "    ]\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": null,\n" +
//                "    \"comments\": \"物料规格\",\n" +
//                "    \"defaultValue\": \"\",\n" +
//                "    \"name\": \"material_spec\",\n" +
//                "    \"type\": \"String\",\n" +
//                "    \"group\": [\n" +
//                "      \"general\"\n" +
//                "    ]\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"comments\": \"物料型号\",\n" +
//                "    \"defaultValue\": \"\",\n" +
//                "    \"name\": \"material_model\",\n" +
//                "    \"type\": \"String\",\n" +
//                "    \"group\": [\n" +
//                "      \"general\"\n" +
//                "    ]\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": \"\",\n" +
//                "    \"comments\": \"计划数量\",\n" +
//                "    \"defaultValue\": null,\n" +
//                "    \"name\": \"plan_quantity\",\n" +
//                "    \"type\": \"Integer\"\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": null,\n" +
//                "    \"comments\": \"实际数量\",\n" +
//                "    \"defaultValue\": null,\n" +
//                "    \"name\": \"real_quantity\",\n" +
//                "    \"type\": \"Integer\"\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": \"s2\",\n" +
//                "    \"comments\": \"仓库编码\",\n" +
//                "    \"defaultValue\": \"\",\n" +
//                "    \"name\": \"warehouse_code\",\n" +
//                "    \"type\": \"String\",\n" +
//                "    \"group\": [\n" +
//                "      \"general\"\n" +
//                "    ]\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": null,\n" +
//                "    \"comments\": \"仓库ID\",\n" +
//                "    \"defaultValue\": null,\n" +
//                "    \"name\": \"warehouse_id\",\n" +
//                "    \"type\": \"Integer\"\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": \"s3\",\n" +
//                "    \"comments\": \"库位编码\",\n" +
//                "    \"defaultValue\": \"\",\n" +
//                "    \"name\": \"bin_code\",\n" +
//                "    \"type\": \"String\",\n" +
//                "    \"group\": [\n" +
//                "      \"general\"\n" +
//                "    ]\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"comments\": \"库位ID\",\n" +
//                "    \"defaultValue\": null,\n" +
//                "    \"name\": \"bin_id\",\n" +
//                "    \"type\": \"Integer\"\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": \"\",\n" +
//                "    \"comments\": \"入库状态\",\n" +
//                "    \"defaultValue\": null,\n" +
//                "    \"name\": \"status\",\n" +
//                "    \"type\": \"Integer\"\n" +
//                "  },\n" +
//                "  {\n" +
//                "    \"code\": \"\",\n" +
//                "    \"comments\": \"金额\",\n" +
//                "    \"defaultValue\": null,\n" +
//                "    \"name\": \"money\",\n" +
//                "    \"type\": \"Double\"\n" +
//                "  }\n" +
//                "]";
//        printNameAndComments(json);
    }

}
